#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > energy_lucita_gasci.info <<'%EOF%'
   energy_lucita_gasci
   -------------------
   Molecule:         HBr
   Wave Functions:   RHF, LUCITA CI
   Test Purpose:     Check LUCITA CI energy and NO calculation
                     for two roots, with symmetry
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > energy_lucita_gasci.mol <<'%EOF%'
BASIS
cc-pVDZ
HBr with small basis set

    2    2  X  Y   a
        1.    1
H     0.0000000000            0.0000000000           1.414431
       35.    1
Br    0.0000000000            0.0000000000           0.000000
FINISH
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > energy_lucita_gasci.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTION
**WAVE FUNCTIONS
.HF
.GASCI
*SCF INPUT
.DOUBLY OCCUPIED
 9 4 4 1
*LUCITA
.TITLE
 HBr molecule ground state
.INIWFC
 HF_SCF
.CITYPE
 GASCI
.SYMMET
 1
.MULTIP
 1
.INACTIVE
 7 3 3 1
.GAS SH
 3
 5 8 / 2  1  1  0
 6 8 / 4  2  2  1
 8 8 / 3  1  1  0
.NROOTS
 2
.RSTART
 0
.MAXITR
 16
.MXCIVE
 6
.ANALYZ
.NATORB
.SPDENS
 1
**END OF INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >energy_lucita_gasci.check
cat >>energy_lucita_gasci.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -i -a"
else
   GREP="egrep -i"
fi

# Reading from basis set library:
CRIT1=`$GREP "Basis set used is \"cc-pVDZ\" from the basis set library\." $log | wc -l`
TEST[1]=`expr $CRIT1`
CTRL[1]=1
ERROR[1]="BASIS SET LIBRARY NOT SET UP CORRECTLY"

# Reading molecular geometry:
CRIT1=`$GREP " H .* 1 * x * 0*\.0000000000" $log | wc -l`
CRIT2=`$GREP "2 * y * 0*\.0000000000" $log | wc -l`
CRIT3=`$GREP "3 * z *  2\.6728872127" $log | wc -l`
CRIT4=`$GREP " Br .* 4 * x * 0*\.0000000000" $log | wc -l`
CRIT5=`$GREP "5 * y * 0*\.0000000000" $log | wc -l`
CRIT6=`$GREP "6 * z * 0*\.0000000000" $log | wc -l`
CRIT7=`$GREP "Total number of coordinates: * 6" $log | wc -l`
TEST[2]=`expr $CRIT1  \+ $CRIT2  \+ $CRIT3  \+ $CRIT4  \+ $CRIT5  \+ \
              $CRIT6  \+ $CRIT7`
CTRL[2]=7
ERROR[2]="MOLECULAR GEOMETRY NOT READ CORRECTLY"

# Nuclear repulsion energy:
CRIT1=`$GREP "Nuclear repulsion energy : * 13.0944545036" $log | wc -l`
TEST[3]=`expr $CRIT1`
CTRL[3]=1
ERROR[3]="NUCLEAR REPULSION ENERGY NOT CORRECT"

# Wave function:
CRIT1=`$GREP "Number of closed shell electrons * 36" $log | wc -l`
CRIT2=`$GREP "Number of electrons in active shells * 0" $log | wc -l`
CRIT4=`$GREP "Total number of orbitals * 32" $log | wc -l`
CRIT5=`$GREP "Spin multiplicity and 2 M_S .* 1 * 0" $log | wc -l`
CRIT6=`$GREP "Total number of symmetries * 4" $log | wc -l`
CRIT7=`$GREP "Reference state symmetry * 1" $log | wc -l`
TEST[4]=`expr $CRIT1  \+ $CRIT2  \+ $CRIT4  \+ $CRIT5  \+ \
              $CRIT6  \+ $CRIT7`
CTRL[4]=6
ERROR[4]="INCORRECT SCF WAVE FUNCTION"

# Symmetry:
CRIT1=`$GREP "Number of coordinates in each symmetry: .* 2 * 2 * 2 * 0" $log | wc -l`
CRIT2=`$GREP "Number of orbitals in each symmetry: .* 16 * 7 * 7 * 2" $log | wc -l`
CRIT3=`$GREP "Occupied SCF orbitals .* 9 * 4 * 4 * 1" $log | wc -l`
TEST[5]=`expr $CRIT1  \+ $CRIT2  \+ $CRIT3`
CTRL[5]=3
ERROR[5]="SYMMETRY IS NOT CORRECT"

# SCF energy:
     
CRIT1=`$GREP "Final HF energy: * \-2572\.97024046" $log | wc -l`
TEST[6]=`expr $CRIT1`
CTRL[6]=1
ERROR[6]="SCF ENERGY NOT CORRECT"

# LUCITA setup
CRIT2=` $GREP "Type of calculation \..* GASCI" $log | wc -l`
CRIT3=` $GREP "Number of roots to be obtained \..* 2" $log | wc -l`
CRIT4=` $GREP "Number of active electrons \..* 8" $log | wc -l`
CRIT5=` $GREP "Spin multiplicity \..* 1" $log | wc -l`
TEST[7]=`expr $CRIT2  \+ $CRIT3  \+ $CRIT4  \+ $CRIT5`
CTRL[7]=4
ERROR[7]="SETUP OF LUCITA NOT CORRECT"

# GAS spaces
CRIT1=`$GREP "GAS 1 * 2   1   1   0  * 5  *8" $log | wc -l`
CRIT2=`$GREP "GAS 2 * 4   2   2   1  * 6  *8" $log | wc -l`
CRIT3=`$GREP "GAS 3 * 3   1   1   0  * 8  *8" $log | wc -l`
TEST[8]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[8]=3
ERROR[8]="GAS SPACES NOT CORRECT"

# CI energies
CRIT1=`$GREP " 1  * -2573.1078445... * .....(D|E)-05 * converged" $log | wc -l`
CRIT2=`$GREP " 2  * -2572.7700594... * .....(D|E)-0[45] * converged" $log | wc -l`
TEST[9]=`expr $CRIT1 \+ $CRIT2`
CTRL[9]=2
ERROR[9]="CI CONVERGENCE NOT CORRECT"

CRIT1=`$GREP "Sum =  * 4.00739" $log | wc -l`
CRIT2=`$GREP "Sum =  * 1.98959" $log | wc -l`
CRIT3=`$GREP "Sum =  * 0*.01340" $log | wc -l`
TEST[10]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[10]=4
ERROR[10]="NATORB OCCUPATIONS ROOT 1 NOT CORRECT"

CRIT1=`$GREP "Sum =  * 4.01058" $log | wc -l`
CRIT2=`$GREP "Sum =  * 1.9878[23]" $log | wc -l`
CRIT3=`$GREP "Sum =  * 0*.01375" $log | wc -l`
TEST[11]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[11]=4
ERROR[11]="NATORB OCCUPATIONS ROOT 2 NOT CORRECT"

PASSED=1
for i in 1 2 3 4 5 6 7 8 9 10 11
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
